<template>
    <el-dialog
    title="新增"
    :visible="isShowAddDialog"
    @close="dialogClose"
      >
    <el-form :model="ruleForm" :rules="rules" ref="addForm" label-width="100px">
        <el-row :gutter="24">
            <el-col :span="12">
                <el-form-item label="拍卖师编号" prop="pmsbh">
                  <el-input v-model="ruleForm.pmsbh"></el-input>
              </el-form-item>
            </el-col>
        </el-row>

      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="拍卖师姓名" prop="pmsxm">
                  <el-input v-model="ruleForm.pmsxm"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="证书编号" prop="pmszsbh">
                  <el-input v-model="ruleForm.pmszsbh"></el-input>
              </el-form-item>
          </el-col>
      </el-row>

        <el-row :gutter="24">
            <el-col :span="24">
                <el-form-item label="上传图片" prop="pmszsz">
                    <el-upload
                    class="avatar-uploader"
                    action="/api/auctioneers/addpmszhz"
                    :show-file-list="false"
                    :on-success="handleAvatarSuccess"
                    v-model="ruleForm.pmszsz">
                    <img v-if="ruleForm.pmszsz" :src="ruleForm.pmszsz" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    <div class="el-upload__tip" slot="tip">请按如下要求进行上传：格式：jpeg,jpg,git,bmp,png。</div>
                    </el-upload>
                    <!-- :before-upload="beforeAvatarUpload" -->
                </el-form-item>
            </el-col>
        </el-row>

    </el-form>
  
    <span style="display: flex;">
          <div style="flex: 1"></div>
        <el-button @click="dialogClose">取 消</el-button>
        <el-button type="primary" @click="submitData">确 定</el-button>
    </span>
  
  </el-dialog>
  
  </template>
  
  <script>
  import { addData } from '@/api/auctionManage/auctioneer';
  export default {
      data(){
          return{
            ruleForm: {
                  pmsbh: '',
                  pmsxm: '',
                  pmszsbh: '',
                  pmszsz: ''
                  
              },
              rules:{
                  pmsbh:[
                      {required: true, message: '请输入'}
                  ],
                  pmsxm:[
                      {required: true, message: '请输入'}
                  ],
                  pmszsbh:[
                      {required: true, message: '请输入'}
                  ],
                  pmszsz:[
                      {required: true, message: '请选择'}
                  ],
              }
          }
      },
      props:{
          isShowAddDialog:{
              type:Boolean
          },
      },
      methods: {
          dialogClose(){ 
              this.$emit('dialogClose');
          },
          handleAvatarSuccess(file){
            this.ruleForm.pmszsz = file.data;
          },
          submitData(){
            this.$refs.addForm.validate((valid) => {
                if (!valid) {
                    return ;
                }
                else {
                    addData(this.ruleForm).then((res) => {
                        if(res){
                            console.log(res);
                            this.$message.success("添加成功");
                            this.dialogClose();
                        }
                    })
                }
            });
        },
  
      }
  }
  </script>
  
  <style scoped>
      .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
  </style>
  
  